#include "symboltabledlg.h"

SymbolTableDlg::SymbolTableDlg(QWidget *parent) :
    QDialog(parent)
{
    CreateSymbolTable();

    QGridLayout *mainLayout = new QGridLayout;

    mainLayout->addWidget(SymbolTable, 0, 0);

    setLayout(mainLayout);

    resize(640, 480);

}

void SymbolTableDlg::CreateSymbolTable()
{
    SymbolTable = new QTableWidget(0, 2);
    SymbolTable->setSelectionBehavior(QAbstractItemView::SelectRows);

    QStringList labels;
    labels << tr("Symbol Name") << tr("Address");
    SymbolTable->setHorizontalHeaderLabels(labels);
    SymbolTable->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch);
    SymbolTable->verticalHeader()->hide();
    SymbolTable->setShowGrid(true);

    //connect(SymbolTable, SIGNAL(cellActivated(int,int)),
    //        this, SLOT(openFileOfItem(int,int)));

}

void SymbolTableDlg::ClearSymbolTable()
{
    if(SymbolTable)
    {
        SymbolTable->clear();
        delete SymbolTable;
        CreateSymbolTable();

        this->layout()->addWidget(SymbolTable);
        connect(this->SymbolTable, SIGNAL(cellActivated(int,int)), this, SLOT(GetSymName(int,int)));
    }
}

void SymbolTableDlg::GetSymName(int x, int y)
{
    emit SendSymName(SymbolTable->item(x, y)->text());
}

/*
inline void SymbolTableDlg::LoadSymbolTable(QString &s, quint32 v)
{
    QTableWidgetItem *fileNameItem = new QTableWidgetItem(s);
    fileNameItem->setFlags(fileNameItem->flags() ^ Qt::ItemIsEditable);
    QTableWidgetItem *sizeItem = new QTableWidgetItem(tr("0x%1").arg(v, 8, 16));
    sizeItem->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
    sizeItem->setFlags(sizeItem->flags() ^ Qt::ItemIsEditable);

    int row = SymbolTable->rowCount();
    SymbolTable->insertRow(row);
    SymbolTable->setItem(row, 0, fileNameItem);
    SymbolTable->setItem(row, 1, sizeItem);
}
*/
